﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ATSIDAL;
using ATSModel;

namespace ATSDAL
{
    public class TProductType : BaseRepository<TProductTypeInfo>, ITProductType
    {
        private const string PARM_TPRODUCTTYPE_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_TPRODUCTTYPE_PRODUCTTYPENAME = "@ProductTypeName";
        private const string PARM_TPRODUCTTYPE_PRODUCTTYPESERIALID = "@ProductTypeSerialID";
        private const string PARM_TPRODUCTTYPE_PRODUCTTYPEZTE = "@ProductTypeIsZTE";

        private const string PARM_TPRODUCTTYPE_ISREVIEWCODE = "@IsReviewCode";

        #region 数据检索部分
        public IList<TProductTypeInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("TProductType_select");
        }

        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public TProductTypeInfo LoadEntity<T1>(T1 productTypeId)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = productTypeId;
            return ExcuteSqlToGetEntity("TProductType_selectbyID", parm);
        }

        public IList<TProductTypeInfo> GetbyPID(string productTypeID)
        {
            SqlParameter[] parms = GetPIDParameters();
            parms[0].Value = productTypeID;
            return ExcuteSqlToGetEntities("TProductType_selectbyID", parms);
        }
        


        
        //通过S代码，获取S代码对应的产品类型名称（标签打印软件对接）
        public TProductTypeInfo ProductTypeName_GetbyProductTypeID(string ProductTypeID)
        {
            SqlParameter parm = GetParameter();
            parm.Value = ProductTypeID;
            return ExcuteSqlToGetEntity("WEB_ProductTypeName_GetbyProductTypeID", parm);
        } 
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override TProductTypeInfo GetEntityRecord(SqlDataReader rdr)
        {
            TProductTypeInfo pro = new TProductTypeInfo { ProductTypeID = rdr.GetValue(0).ToString(), ProductTypeName = rdr.GetValue(1).ToString(),
                                                          ProductTypeSerialID = rdr.GetValue(2).ToString(),
                                                          ProductTypeIsZTE = rdr.GetInt32(3),
                                                          IsReviewCode = rdr.GetInt32(4)
            };
            return pro;
        }

        public override TProductTypeInfo GetEntityRecord()
        {
            TProductTypeInfo pro = new TProductTypeInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "TProductType_Insert";
        }

        public override string GetUpdatesp()
        {
            return "TProductType_Update";
        }

        public override string GetDeletesp()
        {
            return "TProductType_Delete";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPEID, SqlDbType.NVarChar, 50);
            return Parm;
        }


        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPENAME, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPESERIALID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPEZTE, SqlDbType.Int),
                    new SqlParameter(PARM_TPRODUCTTYPE_ISREVIEWCODE, SqlDbType.Int)
                };
            return parms;
        }

        public SqlParameter[] GetPIDParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPEID, SqlDbType.NVarChar, 50) 
                };
            return parms;
        }

        public override void SetParameters(TProductTypeInfo productType, params SqlParameter[] Parms)
        {
            Parms[0].Value = productType.ProductTypeID;
            Parms[1].Value = productType.ProductTypeName;
            Parms[2].Value = productType.ProductTypeSerialID;
            Parms[3].Value = productType.ProductTypeIsZTE;
            Parms[4].Value = productType.IsReviewCode;
        }
        #endregion

    }
}
